package com.demo.apparel.controller.uniapp;

import com.demo.apparel.common.Result;
import com.demo.apparel.service.uniapp.TempImageService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/wx/temp")
@Tag(name = "示例图片存储接口", description = "图片存储cos腾旭云")
public class TempImageController {

    private final TempImageService tempImageService;

    public TempImageController(TempImageService tempImageService) {
        this.tempImageService = tempImageService;
    }

    /**
     * 上传临时图片接口，返回图片访问URL
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestParam("file") MultipartFile file,
                         HttpServletRequest request) throws Exception {
        String userId = (String) request.getAttribute("userId");
        String avatarUrl = tempImageService.uploadTempImage(file, userId);
        return Result.success(avatarUrl);
    }
}

